import router from "@/router";
import axios from "axios";
let http=axios.create({
    baseURL: process.env.NODE_ENV == 'production' ? 'http://backend-api-01.newbee.ltd/api/v1' : '/api/v1'
})
//请求拦截
http.interceptors.request.use(function (config) {
    config.headers.token=localStorage.getItem("xftoken")
    return config
},function (error) {
    return Promise.reject(error)
}
);
http.defaults.headers.post['Content-Type'] = 'application/json'
http.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
//响应拦截
http.interceptors.response.use(function (response) {
    let data =response.data;
    if (data.resultCode!=200) {
        // Notify({type:'danger',message:data.message||"系统繁忙"})
      if (data.resultCode===416) {
        if (router.currentRoute.path!="/Login") {
            router.push("/Login")
        }
      }
    }
    return data
},function (error) {
    return Promise.reject(error)
}
)
export default http